package com.desay.pangoo.itmt.utils;

import cn.hutool.core.io.resource.ClassPathResource;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class MockUtils {
    /**
     * 工具方法 获取Mock数据
     *
     * @param path classPath下的相对路径
     * @return 一个JSON字符串
     */
    public static String getJsonStrFromClassPath(String path) {
        ClassPathResource classPathResource = new ClassPathResource(path);
        BufferedReader reader = classPathResource.getReader(StandardCharsets.UTF_8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line).append("\n");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return sb.toString();
    }
}
